<template>
  <div class="page-scan-mana">
    <el-form :inline="true" :model="scanPlanQueryForm" ref="scanPlanQueryForm">
      <div class="pc-page-header">
        <el-form-item>
          <el-select v-model="scanPlanQueryForm.storageId" clearable remote
                     reserve-keyword filterable placeholder="选择仓库" class="pc-input3-col6" value=""
                     :remote-method="searchStorage" @focus="searchStorage()">
            <el-option v-for="item in storageList" :key="item.value" :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
          <el-date-picker class="block"
                          v-model="scanPlanQueryForm.createDate"
                          type="daterange"
                          range-separator="-"
                          start-placeholder="创建开始日期"
                          end-placeholder="创建结束日期"
                          value-format="yyyy-MM-dd"
                          @change="getDate">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="queryDataFn">搜索</el-button>
          <el-button type="primary" @click="refresh('scanPlanQueryForm')">刷新</el-button>
        </el-form-item>
      </div>
    </el-form>
    <egrid border class="page-list"
           :data="tableData"
           :columns="columns"
           :columns-schema="columnsSchema"
           :columns-props="columnsProps">
    </egrid>

    <div class="pc-pagination-panel">
      <pc-pagination ref="pcPagination" :url="pageUrl.queryScanPlanList" :queryData="scanPlanQueryForm"
                     @on-query="queryCallBackFn">
      </pc-pagination>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import PcPagination from 'components/form/pagination';
  import PcButton from 'components/form/button';
  import PcDialog from 'components/dialog';
  import EgridCellView from 'components/wms/comm/EgridCellView.vue';
  // 操作按钮
  var Btn = {
    template: `<div style="display:flex; width: 100%;flex-wrap: wrap">
        <el-button v-permission="['wms:stockmanager:sacnManagement:export']" type="danger" plain @click="exportScanResult(row)">导出码单</el-button>
      </div>`,
    props: ['row'],
    computed: {
    },
    methods: {
      exportScanResult (val) {
        this.$emit('handle-order', val);
      }
    }
  };
  let that;
  export default {
    data () {
      return {
        scanPlanQueryForm: {
          resource: '1', // 通过后台访问接口
          createDate: null,
          storageId: '',
          startDate: null,
          endInDate: null
        },
        tableData: [],
        storageList: [],
        columns: [
          {
            label: '抄码编号',
            prop: 'scanPlanNo'
          },
          {
            label: '仓库',
            prop: 'storageName'
          },
          {
            label: '创建时间',
            prop: 'createdTimeDisplay'
          },
          {
            label: '更新时间',
            prop: 'scanUpdateTimeDisplay'
          },
          {
            label: '抄码数量',
            prop: 'scanTotalCount'
          },
          {
            label: '操作人',
            prop: 'lastOperator'
          },
          {
            label: '操作',
            minWidth: 202,
            fixed: 'right',
            component: Btn, // 'el-button'
            listeners: {
              'handle-order' (data) {
                that.exportScanResult(data);
              }
            },
            propsHandler: function ({ row, col, column }) {
              return {row, col, column};
            }
          }
        ],
        columnsSchema: {
          '抄码数量': {minWidth: 100}
        },
        // columnsProps 用于定义所有 columns 公共的属性，
        // 这里属性可以参考这里： http://element.eleme.io/#/zh-CN/component/table#table-column-attributes
        columnsProps: {
          height: 40,
          minWidth: 150,
          showOverflowTooltip: true,
          component: EgridCellView
        },
        // columnsHandler 可用于在现有的 columns 进行操作，对 columns 进行增删改，这里新增了操作列
        pageUrl: {
          queryScanPlanList: '/maliwms/scan/getScanPlanList'
        }
      };
    },
    components: {
      PcPagination, PcButton, PcDialog
    },
    created () {
      that = this;
    },
    mounted() {
      this.initData();
    },

    methods: {
      closeRefresh() {
        this.successTip('提交成功');
        this.refresh('scanPlanQueryForm');
      },
      initData() {
        this.ajax({
          url: '/maliwms/storage/listStorage',
          type: 'POST',
          data: {},
          success: (res) => {
            setTimeout(() => {
              this.$pcNProgress.done();
            }, 300);
            this.allStorages = res.result.list;
            this.list = this.allStorages.map(item => {
              return {value: item.id, label: item.storageName};
            });
          }
        });
      },
      searchStorage (query) {
        if (query !== '' && query !== undefined) {
          alert(query);
          setTimeout(() => {
            this.storageList = this.list.filter(item => {
              return item.label.toLowerCase()
                .indexOf(query.toLowerCase()) > -1;
            });
          }, 200);
        } else {
          this.storageList = this.list.filter(item => {
            return item.label.toLowerCase();
          });
        }
      },
      getDate() {
        if (this.scanPlanQueryForm.createDate === null) {
          this.scanPlanQueryForm.startDate = '';
          this.scanPlanQueryForm.startDate = '';
        } else {
          this.scanPlanQueryForm.startDate = this.scanPlanQueryForm.createDate[0];
          this.scanPlanQueryForm.endDate = this.scanPlanQueryForm.createDate[1];
        }
      },
      // 表头样式
      getHeaderStyle({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return 'background: #f5f5f5; height: 50px';
        } else {
          return '';
        }
      },
      getRowClass({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return 'background:rgb(245, 245, 245);';
        } else {
          return '';
        }
      },
      openMessage() {
        this.$notify.info({
          title: '自定义位置',
          message: '右下角弹出的消息',
          position: 'bottom-right'
        });
      },
      queryCallBackFn (res) {
        this.tableData = res.result.list;
      },
      queryDataFn () {
        this.$refs.pcPagination.queryListWithPageFn(true);
      },
      refresh (formName) {
        this.$refs[formName].resetFields();
        this.scanPlanQueryForm.createDate = null;
        this.scanPlanQueryForm.storageId = '';
        this.scanPlanQueryForm.startDate = null;
        this.scanPlanQueryForm.endDate = null;
        this.queryDataFn();
      },
      // 导出仓单数据
      exportScanResult (scopeRow) {
        this.exportFile({type: 'POST',
          url: '/maliwms/scan/exportScanResult',
          data: {scanPlanId: scopeRow.id},
          loading: true,
          fileNameStart: '码单'
        });
      }
    }
  };
</script>
<style>
  .page-scan-mana .el-upload-list--picture-card .el-upload-list__item-thumbnail{
    width: 146px;
    height: 146px;
    display: block;
    position:relative;
  }
  .page-scan-mana .el-upload-list--picture-card .el-upload-list__item-thumbnail:before{
    content: "\E614";
    position: absolute;
    top: 18px;
    left: 40px;
    color: #b3b3b3;
    font-size: 60px;
    font-family: "maliiconfont" !important;
  }
  .page-scan-mana .topClassEditInfo .el-upload-list--picture-card .el-upload-list__item .el-icon-close
  {
    display: none;
  }
  .page-scan-mana .topClassEditInfo .el-upload-list--picture-card .el-upload-list__item .el-icon-close-tip
  {
    display: none;
  }
</style>
